<template>
	<view class="set_up">
		<u-grid :border="true" col="3" align="center">
			<u-grid-item v-for="(item,Index) in setUpList" :key="Index" @click="handleClick(item)" bgColor="white"
				class="ddd">
				<text class="grid-text">{{item.name}}</text>
			</u-grid-item>
		</u-grid>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				visible: false,
				setUpList: [{
						name: "个人资料",
						id: 0,
						path: '/pages/setPerson/setPerson'
					},
					{
						name: "收款人信息",
						id: 1,
						path: '/pages/payeeInfo/payeeInfo'
					},
					{
						name: "收货地址",
						id: 2,
						path: '/pages/locationGo/locationGo'
					},
					{
						name: "修改登录密码",
						id: 3,
						path: '/pages/changeOldPassword/changeOldPassword'
					},
					{
						name: "修改支付密码",
						id: 4,
						path: '/pages/changePassword/changePassword'
					},
					// {
					// 	name: "注销账号",
					// 	id: 5
					// },
					{
						name: "查看协议",
						id: 6
					},
				],
			}
		},
		methods: {
			handleClick(item) {
				if (item.id === 5 && uni.getStorageSync("secretKey")) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$http({
						url: "/MemberLogin/sendSms",
						data: {
							templateId: 'SMS_241100166',
							phoneNumberSet: this.userList.userName
						}
					}).then(res => {
						console.log(res)
						if (res.data.code === 200) {
							uni.$u.toast('验证码已发送');
							uni.showModal({ //提醒用户更新
								title: "请输入验证码注销账号？",
								content: "",
								editable: true,
								placeholderText: "请输入验证码",
								success: (resp) => {
									this.$http({
										url: "/member/cancellation",
										method: "GET",
										data: {
											verifyCode: resp.content
										}
									}).then(res => {
										if (res.data.code === 200) {
											uni.showToast({
												title: '注销成功',
												icon: 'success'
											})
											uni.removeStorageSync("secretKey")
											uni.reLaunch({
												url: "/pages/user/user"
											})
										} else {
											uni.showToast({
												title: res.data.message,
												icon: 'error'
											})
										}
									})
								}
							})
						} else {

						}
					})

				} else if (item.id == 6) {
					uni.navigateTo({
						url: "/pages/agreement/agreement"
					})
				} else {
					uni.navigateTo({
						url: item.path
					})
				}
			},
		},
		onLoad() {
			this.$http({
				url: "/member/getMyPage"
			}).then(res => {
				this.userList = res.data.data
			})

		}

	}
</script>

<style lang="scss" scoped>
	@import './setUp.css'
</style>
